package com.mango.amazon;

import com.amazon.AmazonSpiSite;
import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentials;
import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentialsProvider;
import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;
import com.amazon.spapi.catalogItems_2020_12_01.api.CatalogApi;
import com.amazon.spapi.definitionsProductTypes_2020_09_01.api.DefinitionsApi;
import com.amazon.spapi.feeds_2021_06_30.api.FeedsApi;
import com.amazon.spapi.listingsItems_2021_08_01.api.ListingsApi;
import com.amazon.spapi.reports_2021_06_30.api.ReportsApi;
import com.google.common.net.MediaType;

import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_MIGRATION_API;
import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_NOTIFICATIONS_API;

/**
 * 亚马逊API 工厂类
 */
public class APIfactory {

    private static final String TEST_REFRESH_TOKEN = "rToken";
    private static final String TEST_CLIENT_SECRET = "cSecret";
    private static final String TEST_CLIENT_ID = "cId";
    private static final String TEST_ENDPOINT = "https://www.amazon.com/lwa";
    private static final String TEST_SCOPE_1 = SCOPE_NOTIFICATIONS_API;
    private static final String TEST_SCOPE_2 = SCOPE_MIGRATION_API;
    private static final String SELLER_TYPE_SELLER = "seller";
    private static final String SELLER_TYPE_SELLERLESS = "sellerless";
    private static final MediaType EXPECTED_MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8");
    private static final String endpoint = "https://api.amazon.com/auth/o2/token";

    private static final String TEST_ACCESS_KEY_ID = "AKIA5VN36NQQVWDQKU5Z";

    private static final String TEST_SECRET_KEY = "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";
    //美国
    private static final String TEST_REGION = "us-east-1";

    private static final String roleArn = "arn:aws:iam::939381386273:role/amazonApi";

    private static final String roleSessionName = "amazonApi";
    private static final String spiRefreshToken = "Atzr|IwEBINeUJZmB0lpNQRnt3FT7jIt3HHLbA4QCKBXl_Axp5C1Lrg9F0xjW-0OUELJKkPDh_VsIO7sRQV-sCjRZqHVY9HmpygckMNB6AbmFPpiykW1itkTI-rhEXvjbczZGTcSHLM8Olhcl6Yud0CVumu3eeKfaSSCOrF_m00ey3-AaWwqJDdAyrpGWBn4bN2mKDqs3ISRTz1Zv9RNtmpndsR4aOnZOMu4FXNcR6rwvMXYJg7WVth04ISqoTMi6VrTwOJPXARfO_nT4GGDeIZ2h1CDkb0H_dtSnlVffOPOll-u-muJiBHPCHK_5m4_Swu_ON6NZXZw";


    public static com.amazon.spapi.listingsRestrictions_2021_08_01.api.ListingsApi  listingsRestrictionsApi = new com.amazon.spapi.listingsRestrictions_2021_08_01.api.ListingsApi.Builder()
            .awsAuthenticationCredentials(AWSAuthenticationCredentials.builder()
                    //IAM user的accessKeyId
                    .accessKeyId("AKIA5VN36NQQVWDQKU5Z")
                    //IAM user的secretKey
                    .secretKey("DaGHAY+b3/YwtC0OHwNt7G7pxrynKPUfUvT63/J4")
                    //这里按照amazon对不同region的分区填写，例子是北美地区的
                    .region(AmazonSpiSite.US.getAwsRegion())
                    .build())
            .awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider.builder()
                    //IAM role，特别注意：最好用IAM role当做IAM ARN去申请app
                    // 而且IAM user需要添加内联策略STS关联上IAM role，具体操作看：https://www.spapi.org.cn/cn/model2/_2_console.html
                    .roleArn(roleArn) // arn:aws:iam::939381386273:role/amazonApi   arn:aws:iam::446020251947:user/mangoerp          arn:aws:iam::939381386273:user/mangoerp
                    .roleSessionName(roleSessionName)// amazonApi   mangoerp
                    .build())
            .lwaAuthorizationCredentials(LWAAuthorizationCredentials.builder()
                    //申请app后LWA中的clientId
                    .clientId("amzn1.application-oa2-client.2abbca2d57c144129de571c1d2edb204")
                    //申请app后LWA中的clientSecret
                    .clientSecret("dee17e213f136d044198fe848ce72eb894d621bfb40a43aa6e7c2e5eaa862137")
                    //店铺授权时产生的refreshToken或者app自授权生成的
                    .refreshToken(spiRefreshToken)
                    .endpoint(endpoint) // https://api.amazon.com/auth/o2/token
                    .build())
            .endpoint(AmazonSpiSite.US.getSpiEndpoint())
            .build();



    public static ListingsApi listingsApi = new ListingsApi.Builder()
            .awsAuthenticationCredentials(AWSAuthenticationCredentials.builder()
                    //IAM user的accessKeyId
                    .accessKeyId("AKIA5VN36NQQVWDQKU5Z")
                    //IAM user的secretKey
                    .secretKey("DaGHAY+b3/YwtC0OHwNt7G7pxrynKPUfUvT63/J4")
                    //这里按照amazon对不同region的分区填写，例子是北美地区的
                    .region(AmazonSpiSite.US.getAwsRegion())
                    .build())
            .awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider.builder()
                    //IAM role，特别注意：最好用IAM role当做IAM ARN去申请app
                    // 而且IAM user需要添加内联策略STS关联上IAM role，具体操作看：https://www.spapi.org.cn/cn/model2/_2_console.html
                    .roleArn(roleArn) // arn:aws:iam::939381386273:role/amazonApi   arn:aws:iam::446020251947:user/mangoerp          arn:aws:iam::939381386273:user/mangoerp
                    .roleSessionName(roleSessionName)// amazonApi   mangoerp
                    .build())
            .lwaAuthorizationCredentials(LWAAuthorizationCredentials.builder()
                    //申请app后LWA中的clientId
                    .clientId("amzn1.application-oa2-client.2abbca2d57c144129de571c1d2edb204")
                    //申请app后LWA中的clientSecret
                    .clientSecret("dee17e213f136d044198fe848ce72eb894d621bfb40a43aa6e7c2e5eaa862137")
                    //店铺授权时产生的refreshToken或者app自授权生成的
                    .refreshToken(spiRefreshToken)
                    .endpoint(endpoint) // https://api.amazon.com/auth/o2/token
                    .build())
            .endpoint(AmazonSpiSite.US.getSpiEndpoint())
            .build();


    public static FeedsApi feedsApi = new FeedsApi.Builder()
            .awsAuthenticationCredentials(AWSAuthenticationCredentials.builder()
                    //IAM user的accessKeyId
                    .accessKeyId("AKIA5VN36NQQVWDQKU5Z")
                    //IAM user的secretKey
                    .secretKey("DaGHAY+b3/YwtC0OHwNt7G7pxrynKPUfUvT63/J4")
                    //这里按照amazon对不同region的分区填写，例子是北美地区的
                    .region(AmazonSpiSite.US.getAwsRegion())
                    .build())
            .awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider.builder()
                    //IAM role，特别注意：最好用IAM role当做IAM ARN去申请app
                    // 而且IAM user需要添加内联策略STS关联上IAM role，具体操作看：https://www.spapi.org.cn/cn/model2/_2_console.html
                    .roleArn(roleArn) // arn:aws:iam::939381386273:role/amazonApi   arn:aws:iam::446020251947:user/mangoerp          arn:aws:iam::939381386273:user/mangoerp
                    .roleSessionName(roleSessionName)// amazonApi   mangoerp
                    .build())
            .lwaAuthorizationCredentials(LWAAuthorizationCredentials.builder()
                    //申请app后LWA中的clientId
                    .clientId("amzn1.application-oa2-client.2abbca2d57c144129de571c1d2edb204")
                    //申请app后LWA中的clientSecret
                    .clientSecret("dee17e213f136d044198fe848ce72eb894d621bfb40a43aa6e7c2e5eaa862137")
                    //店铺授权时产生的refreshToken或者app自授权生成的
                    .refreshToken(spiRefreshToken)
                    .endpoint(endpoint) // https://api.amazon.com/auth/o2/token
                    .build())
            .endpoint(AmazonSpiSite.US.getSpiEndpoint())
            .build();

    private static ReportsApi reportsApi = new ReportsApi.Builder()
            .awsAuthenticationCredentials(AWSAuthenticationCredentials.builder()
                    //IAM user的accessKeyId
                    .accessKeyId("AKIA5VN36NQQVWDQKU5Z")
                    //IAM user的secretKey
                    .secretKey("DaGHAY+b3/YwtC0OHwNt7G7pxrynKPUfUvT63/J4")
                    //这里按照amazon对不同region的分区填写，例子是北美地区的
                    .region(AmazonSpiSite.US.getAwsRegion())
                    .build())
            .awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider.builder()
                    //IAM role，特别注意：最好用IAM role当做IAM ARN去申请app
                    // 而且IAM user需要添加内联策略STS关联上IAM role，具体操作看：https://www.spapi.org.cn/cn/model2/_2_console.html
                    .roleArn(roleArn) // arn:aws:iam::939381386273:role/amazonApi   arn:aws:iam::446020251947:user/mangoerp          arn:aws:iam::939381386273:user/mangoerp
                    .roleSessionName(roleSessionName)// amazonApi   mangoerp
                    .build())
            .lwaAuthorizationCredentials(LWAAuthorizationCredentials.builder()
                    //申请app后LWA中的clientId
                    .clientId("amzn1.application-oa2-client.2abbca2d57c144129de571c1d2edb204")
                    //申请app后LWA中的clientSecret
                    .clientSecret("dee17e213f136d044198fe848ce72eb894d621bfb40a43aa6e7c2e5eaa862137")
                    //店铺授权时产生的refreshToken或者app自授权生成的
                    .refreshToken(spiRefreshToken)
                    .endpoint(endpoint) // https://api.amazon.com/auth/o2/token
                    .build())
            .endpoint(AmazonSpiSite.US.getSpiEndpoint())
            .build();

    public static DefinitionsApi definitionsApi = new DefinitionsApi.Builder()
            .awsAuthenticationCredentials(AWSAuthenticationCredentials.builder()
                    //IAM user的accessKeyId
                    .accessKeyId("AKIA5VN36NQQVWDQKU5Z")
                    //IAM user的secretKey
                    .secretKey("DaGHAY+b3/YwtC0OHwNt7G7pxrynKPUfUvT63/J4")
                    //这里按照amazon对不同region的分区填写，例子是北美地区的
                    .region(AmazonSpiSite.US.getAwsRegion())
                    .build())
            .awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider.builder()
                    //IAM role，特别注意：最好用IAM role当做IAM ARN去申请app
                    // 而且IAM user需要添加内联策略STS关联上IAM role，具体操作看：https://www.spapi.org.cn/cn/model2/_2_console.html
                    .roleArn(roleArn) // arn:aws:iam::939381386273:role/amazonApi   arn:aws:iam::446020251947:user/mangoerp          arn:aws:iam::939381386273:user/mangoerp
                    .roleSessionName(roleSessionName)// amazonApi   mangoerp
                    .build())
            .lwaAuthorizationCredentials(LWAAuthorizationCredentials.builder()
                    //申请app后LWA中的clientId
                    .clientId("amzn1.application-oa2-client.2abbca2d57c144129de571c1d2edb204")
                    //申请app后LWA中的clientSecret
                    .clientSecret("dee17e213f136d044198fe848ce72eb894d621bfb40a43aa6e7c2e5eaa862137")
                    //店铺授权时产生的refreshToken或者app自授权生成的
                    .refreshToken(spiRefreshToken)
                    .endpoint(endpoint) // https://api.amazon.com/auth/o2/token
                    .build())
            .endpoint(AmazonSpiSite.US.getSpiEndpoint())
            .build();

    private static CatalogApi catalogApi = new CatalogApi.Builder()
            .awsAuthenticationCredentials(AWSAuthenticationCredentials.builder()
                    //IAM user的accessKeyId
                    .accessKeyId("AKIA5VN36NQQVWDQKU5Z")
                    //IAM user的secretKey
                    .secretKey("DaGHAY+b3/YwtC0OHwNt7G7pxrynKPUfUvT63/J4")
                    //这里按照amazon对不同region的分区填写，例子是北美地区的
                    .region(AmazonSpiSite.US.getAwsRegion())
                    .build())
            .awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider.builder()
                    //IAM role，特别注意：最好用IAM role当做IAM ARN去申请app
                    // 而且IAM user需要添加内联策略STS关联上IAM role，具体操作看：https://www.spapi.org.cn/cn/model2/_2_console.html
                    .roleArn(roleArn) // arn:aws:iam::939381386273:role/amazonApi   arn:aws:iam::446020251947:user/mangoerp          arn:aws:iam::939381386273:user/mangoerp
                    .roleSessionName(roleSessionName)// amazonApi   mangoerp
                    .build())
            .lwaAuthorizationCredentials(LWAAuthorizationCredentials.builder()
                    //申请app后LWA中的clientId
                    .clientId("amzn1.application-oa2-client.2abbca2d57c144129de571c1d2edb204")
                    //申请app后LWA中的clientSecret
                    .clientSecret("dee17e213f136d044198fe848ce72eb894d621bfb40a43aa6e7c2e5eaa862137")
                    //店铺授权时产生的refreshToken或者app自授权生成的
                    .refreshToken(spiRefreshToken)
                    .endpoint(endpoint) // https://api.amazon.com/auth/o2/token
                    .build())
            .endpoint(AmazonSpiSite.US.getSpiEndpoint())
            .build();


}
